//
//  LearnHome.swift
//  CrseAsst
//
//  Created by 申铭 on 2024/2/22.
//

import SwiftUI
//import SwiftUIIntrospect

struct LearnHome: View {
    let columns = [
        GridItem(.flexible(minimum: 100, maximum: .infinity), spacing: 20),
        GridItem(.flexible(minimum: 100, maximum: .infinity), spacing: 20)
    ]
    
    var body: some View {
        NavigationView {
            ScrollView {
                LearnHomeHearder(title: "记忆")
                
                LazyVGrid(columns: columns, spacing: 20) {
                    ForEach(MemoryItem.allCases, id: \.self) { item in
                        NavigationLink(destination: FuncView()) {
                            FuncBtn(title: item.rawValue)
                        }
                    }
                }
                .padding(.horizontal)
                
                LearnHomeHearder(title: "计算")
                
                LazyVGrid(columns: columns, spacing: 20) {
                    ForEach(CalcType.allCases, id: \.self) { item in
                        NavigationLink {
                            CalcView(type: item)
                        } label: {
                            FuncBtn(title: item.rawValue)
                        }
                    }
                }
                .padding(.horizontal)
            }
            .navigationBarTitle("练习")
            .navigationBarTitleDisplayMode(.automatic)
            .navigationBarItems(trailing: NavigationLink(destination: {
                LearnMoreView()
            }, label: {
                Label("", systemImage: "ellipsis.circle")
            }))
        }
        
    }
}

struct FuncBtn: View {
    let title: String
    
    var body: some View {
        Text(title)
            .frame(minWidth: 100, maxWidth: .infinity, minHeight: 50)
            .foregroundColor(.primary)
            .background(Color("gray6"))
            .cornerRadius(5)
    }
}

struct LearnHomeHearder: View {
    let title: String
    
    var body: some View {
        HStack {
            Text(title)
                .font(.title3)
            Spacer()
        }
        .padding(EdgeInsets(top: 10, leading: 18, bottom: 10, trailing: 0))
    }
}

#Preview {
    LearnHome()
}
